﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;


namespace DrugStorehouseMIS.DAL
{
    public class MeasuringUnitDAL:IMeasuringUnitDAL
    {
        #region IMeasuringUnitDAL 成员

        public IDataReader Select(int MeasuringUnitNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_MeasuringUnit_Select_By_Num", new SqlParameter[] { new SqlParameter("@MeasuringUnitNum", MeasuringUnitNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }


        public IDataReader Select(string MeasuringUnitName)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_MeasuringUnit_Select_By_Name", new SqlParameter[] { new SqlParameter("@MeasuringUnitName", MeasuringUnitName) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        

        public IDataReader Select()
        {
            try
            {
                return SqlDbHelper.RunSQL_Reader(ConnectionString.ConnString, "Proc_MeasuringUnit_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public DataTable SelectAll()
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_MeasuringUnit_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Insert(string MeasuringUnitName, string MeasuringUnitSymbol)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@MeasuringUnitName",MeasuringUnitName),
                    new SqlParameter("@MeasuringUnitSymbol",MeasuringUnitSymbol)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_MeasuringUnit_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(int MeasuringUnitNum, string MeasuringUnitName, string MeasuringUnitSymbol)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@MeasuringUnitNum",MeasuringUnitNum),
                    new SqlParameter("@MeasuringUnitName",MeasuringUnitName),
                    new SqlParameter("@MeasuringUnitSymbol",MeasuringUnitSymbol)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_MeasuringUnit_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(int MeasuringUnitNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_MeasuringUnit_Delete", new SqlParameter[] { new SqlParameter("@MeasuringUnitNum", MeasuringUnitNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        #endregion
    }
}
